package com.example.travelround.mymusic.main.mine;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.view.View;
import android.widget.TextView;

import com.example.travelround.mymusic.MusicService;
import com.example.travelround.mymusic.R;
import com.example.travelround.mymusic.base.BaseFragment;

import static android.content.Context.BIND_AUTO_CREATE;

/**
 * Created by travelround on 17/3/8.
 */

public class MineFragment extends BaseFragment {

    private Intent serviecIntent;
    private TextView textView;
    private MusicService.MusicBinder musicBinder;
    private ServiceConnection connection;

    @Override
    public int setLayout() {
        return R.layout.fragment_mine;
    }

    @Override
    public void initView(View view) {
        textView = byView(R.id.textMine);
    }

    @Override
    public void initData() {

        connection = new ServiceConnection() {
            @Override
            public void onServiceConnected(ComponentName name, IBinder service) {
                musicBinder = (MusicService.MusicBinder) service;
            }

            @Override
            public void onServiceDisconnected(ComponentName name) {
                musicBinder = null;
            }
        };
        Intent serviceIntent = new Intent(context, MusicService.class);
        context.bindService(serviceIntent, connection, BIND_AUTO_CREATE);

        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                musicBinder.play("http://zhangmenshiting.baidu.com/data2/music/212c4d88eb5e673bfbc295a6ff6cd9a4/242078579/242078579.mp3?xcode=28834dd527075c1daca186416cbdae39");
            }
        });
    }

}
